/**
 * RoleController.java
 */
package org.yate.oa.controller;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.math.NumberUtils;
import org.yate.oa.model.RoleEntity;
import org.yate.oa.service.IRoleService;
import org.yate.oa.utils.Pagination;

/**
 * @author Yate
 * @date Nov 18, 2013
 * @description TODO
 * @version 1.0
 */
@WebServlet(urlPatterns = { "/role/get" }, asyncSupported = true)
public class RoleListController extends RestfulController {

	private IRoleService roleService;
	/* 
	 * (non-Javadoc)
	 * @see org.yate.oa.controller.BaseController#init(javax.servlet.ServletConfig)
	 */
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		this.roleService = (IRoleService) super.springCtx
				.getBean("roleService");
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
	 * , javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int rows = NumberUtils.toInt(req.getParameter("rows"), 1);
		int page = NumberUtils.toInt(req.getParameter("page"), 10);

		Pagination<RoleEntity> d = this.roleService.getEntities(rows, page,
				"", "");

		req.setAttribute("data", d);
		req.getRequestDispatcher("/jsp/roles/list.jsp").forward(req, resp);
	}
	/* 
	 * (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
	
	
}
